package com.foreknow.elm.controller;

import com.foreknow.elm.po.DeliveryAddress;
import com.foreknow.elm.service.impl.DeliveryAddressServiceImpl;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

public class DeliveryAddressController {
    public Object listDeliveryAddressByUserId(HttpServletRequest request){
        List<DeliveryAddress> list = null;
        //获取前台请求参数  /DeliveryAddressController/listDeliveryAddressByUserId?userId=12345671111
        String userId = request.getParameter("userId");
        DeliveryAddressServiceImpl deliveryAddressService = new DeliveryAddressServiceImpl();
        list = deliveryAddressService.listDeliveryAddressByUserId(userId);
        return list;

    }
      //获取前台请求参数  /DeliveryAddressController/getDeliveryAddressById?daId=2
    public DeliveryAddress getDeliveryAddressById(HttpServletRequest request){
        DeliveryAddress deliveryAddress = null;
        DeliveryAddressServiceImpl deliveryAddressService = new DeliveryAddressServiceImpl();
        Integer daId = Integer.parseInt(request.getParameter("daId"));
        deliveryAddress = deliveryAddressService.getDeliveryAddressById(daId);
        return deliveryAddress;
    }

    public Object saveDeliveryAddress(HttpServletRequest request){
        //获取前台请求参数 /DeliveryAddressController/saveDeliveryAddress?contactName=abc&contactSex=1&contactTel=neymar&address=aaa&userId=123456
        DeliveryAddressServiceImpl deliveryAddressService = new DeliveryAddressServiceImpl();
        int i = deliveryAddressService.saveDeliveryAddress(request.getParameter("contactName"), Integer.parseInt(request.getParameter("contactSex")), request.getParameter("contactTel"), request.getParameter("address"), request.getParameter("userId"));
        return i;
    }
    public Object updateDeliveryAddress(HttpServletRequest request){
        //获取前台请求参数 /DeliveryAddressController/updateDeliveryAddress?daId=21&contactName=12121&contactSex=1&contactTel=1222222&address=ttt&userId=1666
        DeliveryAddressServiceImpl deliveryAddressService= new DeliveryAddressServiceImpl();
         int i = deliveryAddressService.updateDeliveryAddress(Integer.parseInt(request.getParameter("daId")),request.getParameter("contactName"),Integer.parseInt(request.getParameter("contactSex")),request.getParameter("contactTel"),request.getParameter("address"),request.getParameter("userId"));
        return i;
    }

    public Object removeDeliveryAddress(HttpServletRequest request){
        //获取前台请求参数  /DeliveryAddressController/removeDeliveryAddress?daId=17
        DeliveryAddressServiceImpl deliveryAddressService = new DeliveryAddressServiceImpl();
        int i = deliveryAddressService.removeDeliveryAddress(Integer.parseInt(request.getParameter("daId")));
        return i;
    }
}
